package com.ljxt.dt.web.servlet.storemanagementservlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljxt.dt.domain.Shelves;
import com.ljxt.dt.domain.Warehouse;
import com.ljxt.dt.service.storemanagementservice.WareHouseService;
import com.ljxt.dt.service.storemanagementservice.impl.WareHouseServiceImpl;
import com.ljxt.dt.util.ServiceUtil;
import com.ljxt.dt.util.ServletUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 唐春劲
 * @version 1.0.0
 * @date 2020-05-19 15:24
 * @copyright 老九学堂
 */

@WebServlet("/wareHouse")
public class ChoiceWareHouseServlet extends HttpServlet {
    private WareHouseService admin = new WareHouseServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      //获取前端传入的需要查的类型
        String type = req.getParameter("type");
        ObjectMapper objectMapper = new ObjectMapper();
        if("仓库".equals(type)){
            List<Warehouse> warehouses =  admin.selectWare();
          resp.getWriter().write(objectMapper.writeValueAsString(warehouses));
        }else if("货架".equals(type)){
            Integer id = ServletUtil.getQueryInt(req,"id");
            List<Shelves> shelves = admin.selectShelves(id);
            resp.getWriter().write(objectMapper.writeValueAsString(shelves));
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
